package com.tt.lcd.qunyangGPRS.dao;


import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class MyUser {
	Mysql mysql;
	public MyUser(Context context){
		mysql=new Mysql(context);
	}
	public static String createSQL = "CREATE TABLE IF NOT EXISTS User (id integer primary key autoincrement,"
			+ "uid varchar(50)," + "name varchar(50))";

	/***
	 * 保存用户名
	 *
	 * @return
	 */
	public String insert(String name) {
		String messge = "插入失败！";
		SQLiteDatabase sd = mysql.getWritableDatabase();
		sd.execSQL("insert into User values (null," + "'temp'" + ",'" + name + "')");
		sd.close();
		messge = "插入成功！";
		return messge;
	}

	/***
	 * 修改
	 *
	 * @return
	 */
	public String updata(String uid) {
		String messge = "修改失败！";
		SQLiteDatabase sd = mysql.getWritableDatabase();



		sd.execSQL("update User set uid='" + uid +"' where uid='temp'");
		sd.close();

		messge = "修改成功！";
		return messge;
	}

	/***
	 * 返回UID
	 *
	 * @return
	 */
	public String selectUID() {
		String uid = "";
		SQLiteDatabase sd = mysql.getWritableDatabase();

		Cursor cur = sd.rawQuery("select * from User", null);

		while (cur.moveToNext()) {
			uid = cur.getString(1);
			break;
		}
		cur.close();
		sd.close();
		if(uid.equals("temp"))uid="";
		return uid;
	}

}
